
#include "OSD.h"


void OSD::drawOSD()
{
	gui.draw_GUI();
}

/*----------------------------------------------------------------------------*/
void OSD::initOSD(int w, int h)
{
	targeting = false;

	gui.init();	

	int butid;

	//create nav windows
	gui.create_window("", "skins/nav.skn", 50, h-50, 150, 50);
       gui.windows[0].set_window_drag(false);
	   butid = gui.windows[0].add_button("", 20, 10, 28, 28, "pop_up.tga", "pop_dn.tga", NULL);
		  butFuncs[butid] = &OSD::populationButtonFunc;
	   butid = gui.windows[0].add_button("", 58, 10, 28, 28, "re_up.tga", "re_dn.tga", NULL);
	      butFuncs[butid] = &OSD::researchButtonFunc;
	   butid = gui.windows[0].add_button("", 96, 10, 28, 28, "prod_up.tga", "prod_dn.tga", NULL);
	      butFuncs[butid] = &OSD::productionButtonFunc;

	gui.create_window("", "skins/nav.skn", 0, h-200, 50, 150);
       gui.windows[1].set_window_drag(false);
	   butid = gui.windows[1].add_button("", 11, 102, 28, 28, "trg_up.tga", "trg_dn.tga", NULL);
	      butFuncs[butid] = &OSD::targetButtonFunc;

    //make little circle thingy
    gui.create_window("", "skins/circle.skn", 0, h-50, 50, 50);
	   gui.windows[2].add_graphic("circle.tga", 50, 50, 0, 50);
       gui.windows[2].set_window_drag(false);



	//create info windows
	gui.create_window(" Population", "skins/nav_w.skn", 100, h-350, 200, 250);
	gui.windows[3].add_textarea("Orgy", 8, 200);
	  butid = gui.windows[3].add_button("<", 90, 200, 12, 12, "btu.tga", "btd.tga", NULL);
	    butFuncs[butid] = &OSD::popOrgyDecBut; 
	  gui.windows[3].add_textarea("80", 130, 200);
	  butid = gui.windows[3].add_button(">", 160, 200, 12, 12, "btu.tga", "btd.tga", NULL);
	    butFuncs[butid] = &OSD::popOrgyIncBut; 
	gui.windows[3].add_textarea("Research", 8, 150);
	  butid = gui.windows[3].add_button("<", 90, 150, 12, 12, "btu.tga", "btd.tga", NULL);
	    butFuncs[butid] = &OSD::popResearchDecBut; 
	  gui.windows[3].add_textarea("10", 130, 150);
	  butid = gui.windows[3].add_button(">", 160, 150, 12, 12, "btu.tga", "btd.tga", NULL);
	    butFuncs[butid] = &OSD::popResearchIncBut;
	gui.windows[3].add_textarea("Production", 8, 100);
	  butid = gui.windows[3].add_button("<", 90, 100, 12, 12, "btu.tga", "btd.tga", NULL);
	    butFuncs[butid] = &OSD::popProdDecBut; 
	  gui.windows[3].add_textarea("10", 130, 100);
	  butid = gui.windows[3].add_button(">", 160, 100, 12, 12, "btu.tga", "btd.tga", NULL);
	    butFuncs[butid] = &OSD::popProdIncBut;
	gui.windows[3].set_window_drag(false);
	gui.windows[3].set_visibility(false);

	gui.create_window(" Production", "skins/nav_w.skn", 120, h-370, 200, 250);
	butid = gui.windows[4].add_button("   Build Missle", 30, 200, 140, 14, "btu.tga", "btd.tga", NULL);
	  butFuncs[butid] = &OSD::prodProdMissleBut;
    butid = gui.windows[4].add_button("   Build Shield", 30, 150, 140, 14, "btu.tga", "btd.tga", NULL);
	  butFuncs[butid] = &OSD::prodProdShieldBut;
	gui.windows[4].add_textarea("Current Production Progress:", 20, 100);
	gui.windows[4].add_textarea("50%", 80, 50);
	gui.windows[4].set_window_drag(false);
	gui.windows[4].set_visibility(false);

	gui.create_window(" Research", "skins/nav_w.skn", 140, h-390, 200, 250);
	butid = gui.windows[5].add_button("  Research Missle", 30, 200, 140, 14, "btu.tga", "btd.tga", NULL);
	  butFuncs[butid] = &OSD::prodRdMissleBut;
    butid = gui.windows[5].add_button("  Research Shield", 30, 150, 140, 14, "btu.tga", "btd.tga", NULL);
	  butFuncs[butid] = &OSD::prodRdShieldBut;
	gui.windows[5].add_textarea("Current Research Progress:", 20, 100);
	gui.windows[5].add_textarea("50%", 80, 50);
	gui.windows[5].set_window_drag(false);
	gui.windows[5].set_visibility(false);
}

/*----------------------------------------------------------------------------*/
void OSD::initOSD(int w, int h, int moonViewHeight)
{
	initOSD(w, h);
	mvh = moonViewHeight;

	//create view screen window
    gui.create_window("", "skins/nav.skn", 0, -2, w, moonViewHeight+8);
	  gui.windows[6].set_window_drag(false);
}

/*----------------------------------------------------------------------------*/
bool OSD::checkClick(int button, int state, int x, int y) {

	int butClicked = 0;

	if ( (butClicked = gui.check_click_event(button, state, x, y-mvh)) >= 100)
	{
		if (butFuncs.find(butClicked) != butFuncs.end())
		{
			//printf("go\n");
		    (this->*(butFuncs[butClicked]))((void*)butClicked);
		}
		return true;
	}
	
	return false;
}

void OSD::checkDrag(int x, int y) {
	gui.check_drag_event(x, y-mvh);
}

/*----------------------------------------------------------------------------*/
bool OSD::isTarget() { 
	if (targeting)
	{
		targeting = false;
		return true;		
	}

	return false;
}

/////////////////////////////////////////////////
/*----------------------------------------------------------------------------*/
void* OSD::populationButtonFunc(void*) {

	if (gui.windows[3].visible)
	{
		gui.windows[3].set_visibility(false);
		gui.windows[3].set_window_drag(false);
	}
	else
	{
		gui.windows[3].set_visibility(true);
		gui.windows[3].set_window_drag(true);
	}

	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::researchButtonFunc(void*) {

	if (gui.windows[5].visible)
	{
		gui.windows[5].set_visibility(false);
		gui.windows[5].set_window_drag(false);
	}
	else
	{
		gui.windows[5].set_visibility(true);
		gui.windows[5].set_window_drag(true);
	}

	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::productionButtonFunc(void*) {

	if (gui.windows[4].visible)
	{
		gui.windows[4].set_visibility(false);
		gui.windows[4].set_window_drag(false);
	}
	else
	{
		gui.windows[4].set_visibility(true);
		gui.windows[4].set_window_drag(true);
	}

	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::targetButtonFunc(void*) {
	targeting = true;
	
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::popOrgyDecBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::popOrgyIncBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::popResearchDecBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::popResearchIncBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::popProdDecBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::popProdIncBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::prodRdMissleBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::prodRdShieldBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::prodProdMissleBut(void*) {
	return NULL;
}

/*----------------------------------------------------------------------------*/
void* OSD::prodProdShieldBut(void*) {
	return NULL;
}